﻿namespace Chain.BLL
{
    using Chain.DAL;
    using Chain.Model;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data;
    using System.Runtime.InteropServices;

    public class CouponList
    {
        private readonly Chain.DAL.CouponList dal = new Chain.DAL.CouponList();

        public int Add(Chain.Model.CouponList model)
        {
            return this.dal.Add(model);
        }

        public List<Chain.Model.CouponList> DataTableToList(DataTable dt)
        {
            List<Chain.Model.CouponList> list = new List<Chain.Model.CouponList>();
            int count = dt.Rows.Count;
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    Chain.Model.CouponList item = this.dal.DataRowToModel(dt.Rows[i]);
                    if (item != null)
                    {
                        list.Add(item);
                    }
                }
            }
            return list;
        }

        public bool DataUpdateTran(ArrayList sqlArray)
        {
            return this.dal.DataUpdateTran(sqlArray);
        }

        public bool Delete(int CID)
        {
            return this.dal.Delete(CID);
        }

        public bool DeleteList(string CIDlist)
        {
            return this.dal.DeleteList(CIDlist);
        }

        public bool Exists(int CID)
        {
            return this.dal.Exists(CID);
        }

        public DataSet GetAllList()
        {
            return this.GetList("");
        }

        public DataSet GetCouponDetail(string strWhere)
        {
            return this.dal.GetCouponDetail(strWhere);
        }

        public DataSet GetList(string strWhere)
        {
            return this.dal.GetList(strWhere);
        }

        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return this.dal.GetList(Top, strWhere, filedOrder);
        }

        public DataSet GetListSP(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetListSP(PageSize, PageIndex, strWhere, out resCount);
        }

        public int GetMaxId()
        {
            return this.dal.GetMaxId();
        }

        public DataSet GetMemInfoListSP(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetMemInfoListSP(PageSize, PageIndex, strWhere, out resCount);
        }

        public Chain.Model.CouponList GetModel(string CouPon)
        {
            Chain.Model.CouponList model = this.dal.GetModel(CouPon);
            Chain.Model.Coupon coupon2 = new Chain.BLL.Coupon().GetModel(Convert.ToInt32(model.CouPonID));
            model.CouponMinMoney = coupon2.CouponMinMoney;
            model.CouponNumber = coupon2.CouponNumber;
            model.CouponStart = coupon2.CouponStart;
            model.CouponEnd = coupon2.CouponEnd;
            model.CouponDayNum = coupon2.CouponDayNum;
            model.CouponType = coupon2.CouponType;
            model.CouponEffective = coupon2.CouponEffective;
            return model;
        }

        public List<Chain.Model.CouponList> GetModelList(string strWhere)
        {
            DataSet list = this.dal.GetList(strWhere);
            return this.DataTableToList(list.Tables[0]);
        }

        public int GetRecordCount(string strWhere)
        {
            return this.dal.GetRecordCount(strWhere);
        }

        public bool Update(Chain.Model.CouponList model)
        {
            return this.dal.Update(model);
        }
    }
}

